home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_glimpse.idb / usr / freeware / src / glimpse-3.0 / libtemplate / template / mktemplate.z / mktemplate
Text File  |  1997-09-09  |  4KB  |  94 lines

  1. : # *-*-perl-*-*
  2.     eval 'exec perl -S $0 "$@"'
  3.     if $running_under_some_shell;  
  4. #
  5. #  mktemplate - Converts an easy-to-write template into a SOIF template.
  6. #               Not very robust.
  7. #
  8. #  Usage: mktemplate [file ...]
  9. #
  10. #  Input format: 
  11. #
  12. #      @FILE { url
  13. #      Attribute-Name-1:\tDATA
  14. #      Attribute-Name-2:\tDATA
  15. #      ...
  16. #      Attribute-Name-n:\tDATA
  17. #      }
  18. #
  19. #  The Attributes must begin in column 0 and have one tab after the colon.
  20. #  And the DATA must be on a single line.
  21. #
  22. #  Darren Hardy, hardy@cs.colorado.edu, May 1994
  23. #
  24. #######################################################################
  25. #
  26. #  Copyright (c) 1994.  All rights reserved.
  27. #          Mic Bowman of Transarc Corporation.
  28. #          Peter Danzig of the University of Southern California.
  29. #          Darren R. Hardy of the University of Colorado at Boulder.
  30. #          Udi Manber of the University of Arizona.
  31. #          Michael F. Schwartz of the University of Colorado at Boulder.
  32. #  
  33. #  This copyright notice applies to all code in Harvest other than subsystems
  34. #  developed elsewhere, which contain other copyright notices in their source
  35. #  text.
  36. #  
  37. #  The Harvest software was developed by the Internet Research Task Force
  38. #  Research Group on Resource Discovery (IRTF-RD).  The Harvest software may
  39. #  be used for academic, research, government, and internal business purposes
  40. #  without charge.  The Harvest software may not be sold or distributed to
  41. #  commercial clients or partners without explicit permission from the
  42. #  copyright holders.
  43. #  
  44. #  The Harvest software is provided "as is", without express or implied
  45. #  warranty, and with no support nor obligation to assist in its use,
  46. #  correction, modification or enhancement.  We assume no liability with
  47. #  respect to the infringement of copyrights, trade secrets, or any patents,
  48. #  and are not responsible for consequential damages.  Proper use of the
  49. #  Harvest software is entirely the responsibility of the user.
  50. #  
  51. #  For those who are using Harvest for non-commercial purposes, you may make
  52. #  derivative works, subject to the following constraints:
  53. #          1. You must include the above copyright notice and these
  54. #             accompanying paragraphs in all forms of derivative works, 
  55. #             and any documentation and other materials related to such
  56. #             distribution and use acknowledge that the software was
  57. #             developed at the above institutions.
  58. #          2. You must notify IRTF-RD regarding your distribution of the
  59. #             derivative work.
  60. #          3. You must clearly notify users that your are distributing a
  61. #             modified version and not the original Harvest software.
  62. #          4. Any derivative product is also subject to the restrictions of
  63. #             the copyright, including distribution and use limitations.
  64. #
  65. #######################################################################
  66. while (<>) {
  67.     next if (/^\n/o);
  68.     do print_template() if (/^}/o);
  69.     $top_line = $_ if (/^\@\w+/o);
  70.     do grab_av($_) if (/^\w+/o);
  71. }
  72.  
  73. sub grab_av {
  74.     local($line) = @_;
  75.     $attribute = $1, $data = $2 if ($line =~ /^([^:]*):\t(.*)$/o);
  76.     $attribute =~ s/\{\d+\}//;    # remove length if present
  77.     $values{$attribute} = $data;
  78. }
  79.  
  80. sub print_template {
  81.     print $top_line;
  82.     foreach $k (sort keys %values) {
  83.         next if (length($values{$k}) < 1);
  84.         print $k, "{" , length($values{$k}) , "}:\t";
  85.         print "$values{$k}\n";
  86.     }
  87.     print "}\n\n";
  88.  
  89.     undef $top_line;
  90.     foreach $k (sort keys %values) {
  91.         undef $values{$k};
  92.     }
  93. }
  94.